/**
 * redis key 常量
 */
const RedisKeysConstant = {
	// 用户登录认证信息
	userAuthInfo: "auth:user:${0}",
    // 文件预览
	filePreview: "file:preview:${0}",
	// 文件预览所有keys
	filePreviewKeys: "file:preview:keys",
    // 用户扫码加入群组
	familyScanSign: "family:scan_sign:${0}",
    // 家庭组邀请码
    familyInvitationNumber: "family:invitation_number:${0}",
    // 所有邀请码的键
    familyInvitationNumberKeys: "family:invitation_number:keys",
    // 用户购物车
    userShoppingCart: "shopping_cart:${0}:${1}"
};

for (const key in RedisKeysConstant) {
	const regex = /\$\{(\d+)\}/g;
	// 判断是否为模板
	if (regex.exec(RedisKeysConstant[key])) {
		const template = RedisKeysConstant[key];
		Object.defineProperty(RedisKeysConstant, key, {
			get() {
				return function parseFun(...values) {
					values = values || [];
					return template.replace(regex, (match, p1) => {
						const index = parseInt(p1, 10);
						return values[index] || match;
					});
				};
			},
			set(newValue) {
				RedisKeysConstant[key] = newValue;
			}
		});
	}
}

module.exports = RedisKeysConstant;
